home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
ftp.cs.arizona.edu
/
ftp.cs.arizona.edu.tar
/
ftp.cs.arizona.edu
/
icon
/
newsgrp
/
group93b.txt
/
000092_icon-group-sender _Sat May 15 20:32:40 1993.msg
< prev
next >
Wrap
Internet Message Format
|
1993-06-16
|
2KB
Received: from owl.CS.Arizona.EDU by cheltenham.cs.arizona.edu; Mon, 17 May 1993 07:43:00 MST
Received: by owl.cs.arizona.edu; Mon, 17 May 1993 07:42:58 MST
Message-Id: <9305160132.AA01794@relay2.UU.NET>
Subject: Re: string stripping
To: uunet!cs.arizona.edu!icon-group@uunet.UU.NET (Icon News Group)
Date: Sat, 15 May 1993 20:32:40 -0500 (CDT)
From: Jerry Nowlin <isidev!nowlin@uunet.UU.NET>
X-Mailer: ELM [version 2.4 PL21]
Content-Type: text
Content-Length: 1577
Status: R
Errors-To: icon-group-errors@cs.arizona.edu
> John David Stone Writes...
>
> For stripping hyphens and dots out of a string, Steve Holden
> suggests:
> full ? {
> while bare ||:= tab(many(~badchars)) do
> tab(many(badchars))
> }
>
> which is tempting, but incorrectly sets bare to "" whenever the value of
> full begins with a dot or hyphen.
I'm often amazed at how compact you can implement what appear to be
complicated algorithms in Icon. String scanning sometimes seems like there
has to be a more elegant way but look how cool it is already! There are
two ways I could make this work. Both require more code. The first is
more straightforward:
full ? until pos(0) do {
bare ||:= tab(many(~badchars))
tab(many(badchars))
}
Notice that the order in which the two matching expressions occur makes no
difference. The second solution requires an initial attempt to skip over
badchars and is closer to the original:
full ? {
tab(many(badchars))
while bare ||:= tab(many(~badchars)) do
tab(many(badchars))
}
I like the first solution. Fewer lines, less mess, incomplete sentence.
Both use the principle that failure does not have to be a bad thing. I
know I know...I submitted a code fragment. Anyone who can't reconstitute
this on their own just email me for a complete program.
Jerry Nowlin - uunet!isidev!nowlin - isidev!nowlin@uunet.uu.net